<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
	template="/WEB-INF/templates/default.xhtml">
	<ui:define name="content">

		<h1>Servicebook Web</h1>
		
		<h2>User Data</h2>
		<h:form id="newUserForm">
			<p>
				<h:panelGroup rendered="#{not empty newUser}">
					<h:panelGrid columns="3">
						<h:outputText value="Full name :" />
						<h:outputText id="userFullName" value="#{newUser.person.personName}" />
						<h:message for="userFullName" errorClass="invalid" />

						<h:outputText value="User name :" />
						<h:inputText id="userName" value="#{newUser.userName}" />
						<h:message for="userName" errorClass="invalid" />

						<h:outputText value="e-mail :" />
						<h:inputText id="email" value="#{newUser.email}" />
						<h:message for="email" errorClass="invalid" />

						<h:outputText value="password :" />
						<h:inputSecret id="userPassword" value="#{newUser.password}" />
						<h:message for="userPassword" errorClass="invalid" />

						<h:outputText value="re-password :" />
						<h:inputSecret id="userRePassword" value="#{userController.rePassword}" />
						<h:message for="userRePassword" errorClass="invalid" />
						
						<h:outputText value="Role :" />
						<h:selectOneMenu value="#{newUser.role.roleId}" >
							<f:selectItem itemLabel="Role"/>
							<f:selectItems value="#{userController.selectRole()}" var="_role" itemValue="#{_role.roleId}" itemLabel="#{_role.roleName}" />
						</h:selectOneMenu>
							
							<h:commandButton action="#{userController.saveUser}" value="Save" id="saveUserButton" />
							<h:commandButton action="#{userController.cancelUser}" value="Cancel" />
					
					</h:panelGrid>
				</h:panelGroup>
			</p>
		</h:form>

		<h2>Members</h2>
		<h:panelGroup rendered="#{empty clients}">
			<em>No registered members.</em>
		</h:panelGroup>
		<h:dataTable var="_client" value="#{clients}" rendered="#{not empty clients}" styleClass="simpletablestyle">
			<h:column>
				<f:facet name="header">Id</f:facet>
                #{_client.personId}
            </h:column>
			<h:column>
				<f:facet name="header">Name</f:facet>
                #{_client.personName}
            </h:column>
			<h:column>
				<f:facet name="header">Address</f:facet>
                #{_client.address}
            </h:column>
			<h:column>
				<f:facet name="header">Phone #</f:facet>
                #{_client.phone}
            </h:column>
			<h:column>
				<f:facet name="header">REST URL</f:facet>
				<a href="#{request.contextPath}/rest/members/#{_client.personId}">/rest/members/#{_client.personId}</a>
			</h:column>
			<f:facet name="footer">
            REST URL for all members: <a href="#{request.contextPath}/rest/members">/rest/members</a>
			</f:facet>
		</h:dataTable>

	</ui:define>
</ui:composition>